package com.i8office.android.zhihuixinwu.module.presenter;

import android.text.TextUtils;

import com.cyan.tools.callback.SimpleCallback;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.module.contract.ModifyOpinionContract;
import com.i8office.android.zhihuixinwu.module.model.ModifyOpinionModel;
import com.socks.library.KLog;

import java.util.Map;

/**
 * Created by pc on 2018/7/8.
 */

public class ModifyOpinionPresenter extends BasePresenterImpl<ModifyOpinionContract.View> implements ModifyOpinionContract.Presenter {
    private ModifyOpinionContract.Model model;

    public ModifyOpinionPresenter(ModifyOpinionContract.View view) {
        super(view);
        model = new ModifyOpinionModel();
    }

    @Override
    public void modify(Map<String, String> params) {
        addDisposable(model.modify(new SimpleCallback<Code>(mView){
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                mView.toast(msg);
                mView.modifyFailed();
            }

            @Override
            public void requestSuccess(Code data) {
                super.requestSuccess(data);
                if (data.isSucceed()) {
                    mView.modifySuccess();
                }else {
                    if(!TextUtils.isEmpty(data.getMessage())){
                        mView.toast(data.getMessage());
                    }else{
                        mView.toast(data.getMessage());
                    }
                }

            }
        },params));
    }

}
